package com.ucode.model.hrm.form;

import com.ucode.tool.validator.InEnum;
import com.ucode.tool.validator.Mobile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;

@Schema(description = "人力资源系统 - 客户项目Form")
@Data
@EqualsAndHashCode
@ToString(callSuper = true)
public class HrmCustomerProjectForm {

    /**
     * 客户企业ID
     */
    @Schema(description = "客户企业ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "客户企业ID不能为空")
    private Long customerCompanyId;
    /**
     * 项目名称
     */
    @Schema(description = "项目名称", example = "华为", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "项目名称不能为空")
    @Size(max = 100, message = "项目名称不能超过 100 个字符")
    private String projectName;
    /**
     * 项目开始时间
     */
    @Schema(description = "项目开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "项目开始时间不能为空")
    private LocalDateTime startDate;
    /**
     * 项目结束时间
     */
    @Schema(description = "项目结束时间", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDateTime endDate;
    /**
     * 项目状态
     * @see com.ucode.model.hrm.enums.HrmCustomerProjectStatusEnum
     */
    @Schema(description = "项目状态", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "项目状态不能为空")
    @InEnum( value= com.ucode.model.hrm.enums.HrmCustomerProjectStatusEnum.class)
    private Integer status;
    /**
     * 项目经理
     */
    @Schema(description = "项目经理", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 50, message = "项目经理不能超过 50 个字符")
    private String projectManager;
    /**
     * 项目经理手机号
     */
    @Schema(description = "项目经理手机号",  requiredMode = Schema.RequiredMode.AUTO)
    @Mobile
    private String mobile;
    /**
     * 项目经理性别
     *
     * 枚举类 {@link com.ucode.tool.base.enums.SexEnum}
     */
    @Schema(description = "用户性别", requiredMode = Schema.RequiredMode.AUTO)
    @InEnum(value= com.ucode.tool.base.enums.SexEnum.class)
    private Integer sex;
    /**
     * 项目经理账号
     */
    @Schema(description = "项目经理账号", example = "zhangsan", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 20, message = "客户账号不能超过 20 个字符")
    private String projectAccount;
    /**
     * 服务内容
     */
    @Schema(description = "服务内容", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 500, message = "服务内容不能超过 500 个字符")
    private String serviceContent;
    /**
     * 备注
     */
    @Schema(description = "备注", requiredMode = Schema.RequiredMode.AUTO)
    @Size(max = 500, message = "备注不能超过 500 个字符")
    private String remark;

    /**
     * 归属管理员ID
     */
    @Schema(description = "归属管理员ID", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "归属管理员ID不能为空")
    private Long ownerAdminId;


    @AssertTrue(message = "结束时间必须要大于开始时间")
    public boolean isTimeIntervalCheck() {
        if(this.endDate == null){
            return true;
        }
        if(this.endDate.isAfter(this.startDate)){
            return true;
        }
        return false;
    }
}
